<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS For</title>
</head>
<body>
    <script>
        cars=["BMW","Volvo","Saab","Ford"];
        for (var i = 0; i< car.length;i++){
            document.write(cars[i] + "<br/>")
        }

        /*
        * for in
        * JavaScript for/in 语句循环遍历对象的属性：
        * */
        function testForIn() {
            var x;
            var txt = ""
            var person={fname:"John",lname:"Doe",age:25};
            for (x in person){
                txt = txt + x
            }
            document.getElementById("demo").innerHTML = txt;
        }

    </script>

    <p>点击下面的按钮，循环遍历对象 "person" 的属性。</p>
    <button onclick="testForIn()">点击这里</button>
    <p id="demo"></p>
</body>
</html>